package com.th.controller;

import com.th.common.domain.DesignTask;
import com.th.service.DesignTaskService;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @author ViTe
 * @create 2023/6/17 - 20:37
 */
@RestController
@Api(tags = "设计任务接口")
@RequestMapping("/api/design_task")

public class DesignTaskController {

    @Resource
    private DesignTaskService designTaskService;


    /**
     * 查询所有设计任务列表
     */
    @GetMapping("/list")
    public List<DesignTask> DesignTaskList() {
        return designTaskService.list();
    }

    /**
     * 查询8个设计任务
     */
    @GetMapping("/list8")
    public List<DesignTask> DesignTaskList8() {
        List<DesignTask> list = designTaskService.list();
        List<DesignTask> list8 = new ArrayList<>();
        int size = Math.min(8, list.size());
        if (size > 0) {
            list8 = list.subList(0, size);
        }
        return list8;
    }

    /**
     * 根据 id 查询单个设计任务
     */
    @GetMapping("/get")
    public DesignTask getDesignTaskByid(Long id){
        DesignTask designTask = designTaskService.getById(id);
        return designTask;
    }
}
